package com.bytz.modules.hikvision.callBack;

import com.bytz.modules.hikvision.HCNetSDK;
import com.sun.jna.Pointer;


//报警回调函数实现类：用于接收人脸识别比对结果
public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {

    @Override
    public boolean invoke(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
        // 刷卡、刷脸、指纹等认证方式对应门禁主机报警信息，回调函数中获取的报警类型(lCommand)为COMM_ALARM_ACS
        if (lCommand == HCNetSDK.COMM_ALARM_ACS) {
            //门禁主机报警信息
            // 创建对象strACSInfo
            HCNetSDK.NET_DVR_ACS_ALARM_INFO strACSInfo = new HCNetSDK.NET_DVR_ACS_ALARM_INFO();
            // 将strACSInfo对象写入内存
            strACSInfo.write();
            // 获取strACSInfo对象指针
            Pointer pACSInfo = strACSInfo.getPointer();
            // 将内存中pAlarmInfo写入strACSInfo对象指定位置
            pACSInfo.write(0, pAlarmInfo.getByteArray(0, strACSInfo.size()), 0, strACSInfo.size());
            // 从strACSInfo对象中读取数据
            strACSInfo.read();
            // 温度信息
            HCNetSDK.NET_DVR_ACS_EVENT_INFO_EXTEND_V20 temperatureInfo = new HCNetSDK.NET_DVR_ACS_EVENT_INFO_EXTEND_V20();
            temperatureInfo.write();
            Pointer temperatureInfoPointer = temperatureInfo.getPointer();
            temperatureInfoPointer.write(0, strACSInfo.pAcsEventInfoExtendV20.getByteArray(0, temperatureInfo.size()), 0, temperatureInfo.size());
            temperatureInfo.read();
            // 5(0x5)事件 75(0x4b)人脸认证通过
            if (strACSInfo.dwMajor == 5 && strACSInfo.dwMinor == 75) {
                String ip = new String(pAlarmer.sDeviceIP).trim();
                String punchTime = strACSInfo.struTime.toStringTime();
                //工号如果以0开头的设备会将0给去掉，这是个坑
                String empCode = Integer.toString(strACSInfo.struAcsEventInfo.dwEmployeeNo);
                //一定要加trim(),将多余的空格去掉，不然根据这个卡号去数据查数据的时候肯定会出现：期望xx,实际xxx
                String cardNo = new String(strACSInfo.struAcsEventInfo.byCardNo).trim();
                System.out.println(ip + punchTime + empCode + cardNo);
                // TODO 其他业务逻辑

            }
        }
        return true;
    }
}